package com.example.demo.controller;

import com.example.demo.entity.Student;
import com.example.demo.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/student")
public class StudentController {
    @Autowired
    StudentService studentService;

    @GetMapping("/all/")
    public List<Student>findAll(){
        return studentService.findAll();
    }
    @GetMapping("/{id}")
    public Student findById(@PathVariable Integer id){
        return studentService.findById(id);
    }
    @PostMapping
    public Student insert(@RequestBody Student student){
        return studentService.insert(student);
    }
    @DeleteMapping("/{id}")
    public void deleteById(@PathVariable Integer id){
        studentService.deleteById(id);
    }
    @PutMapping("/{id}")
    public Student update(@PathVariable Integer id,@RequestBody Student student){
        return  studentService.update(student);
    }



}
